package com.windgo.controller.admin;

import com.windgo.bean.bo.GoodsCreateBo;
import com.windgo.bean.MarketGoods;
import com.windgo.bean.bo.OrderCommentReplyBo;
import com.windgo.bean.vo.CatAndBrandVo;
import com.windgo.bean.vo.GoodsDetailVo;
import com.windgo.bean.common.BasePageInfo;
import com.windgo.bean.common.BaseRespVo;
import com.windgo.bean.common.CommonData;
import com.windgo.service.GoodsService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author:ZhouXin
 * @Date:2022/10/11 20:02
 * @Description:
 **/
@RestController
@RequestMapping("admin/goods")
public class GoodsController {

    @Autowired
    GoodsService goodsService;


    /**
     * 商品模块的list功能
     * @param info:分页信息
     * @param goodsId:商品id精确查询
     * @param goodsSn:商品编号模糊查询
     * @param name:商品名称模糊查询
     * @return
     */
    @GetMapping("list")
    @RequiresPermissions("perms[admin:goods:list]")
    public BaseRespVo list(BasePageInfo info,Integer goodsId,Integer goodsSn,String name){
        if (info.getLimit()==0){
            CommonData<MarketGoods> data=goodsService.listLimit();
            return BaseRespVo.ok(data);
        }
        CommonData<MarketGoods> data=goodsService.list(info,goodsId,goodsSn,name);
        return BaseRespVo.ok(data);
    }

    /**
     * 商品模块的detail接口
     * @param id
     * @return
     */
    @GetMapping("detail")
    public BaseRespVo detail(Integer id){
        GoodsDetailVo data=goodsService.detail(id);
        return BaseRespVo.ok(data);
    }

    /**
     * 获取所有的商品分类
     * @return
     */
    @GetMapping("catAndBrand")
    public BaseRespVo catAndBrand(){
        CatAndBrandVo data =goodsService.catAndBrand();
        return BaseRespVo.ok(data);
    }

    /**
     * 创建商品信息
     * @return
     */
    @PostMapping("create")
    @RequiresPermissions("perms[admin:goods:create]")
    public BaseRespVo create(@RequestBody GoodsCreateBo goodsCreateBo){
        goodsService.create(goodsCreateBo);
        return BaseRespVo.ok();
    }

    /**
     *
     * @param goodsCreateBo
     * @return
     */
    @PostMapping("update")
    @RequiresPermissions("perms[admin:goods:update]")
    public BaseRespVo update(@RequestBody GoodsCreateBo goodsCreateBo){
        goodsService.update(goodsCreateBo);
        return BaseRespVo.ok();
    }

    @PostMapping("delete")
    @RequiresPermissions("perms[admin:goods:delete]")
    public BaseRespVo delete(@RequestBody MarketGoods marketGoods){
        Integer goodsId = marketGoods.getId();
        goodsService.delete(goodsId);
        return BaseRespVo.ok();
    }

}